package com.du.stutestsys.controller.Administrator;

import com.du.stutestsys.controller.BaseControler;
import com.du.stutestsys.entity.Subject;
import com.du.stutestsys.service.Administrator.SubjectService;
import com.du.stutestsys.util.PageUtil;
import com.du.stutestsys.util.DuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

//科目管理
@Controller
public class SubjectController extends BaseControler {
    @Autowired
    SubjectService subjectService;


    @PostMapping("admin/addSubject")
    public String addSubject(@RequestBody(required = false) Subject subject){
        return DuUtil.success(subjectService.addSubject(subject)).toJSONString();
    }


    @PostMapping("admin/updateSubject")
    public String updateSubject(@RequestBody(required = false)  Subject subject){
        return DuUtil.success(subjectService.updateSubject(subject)).toJSONString();
    }

    @GetMapping("admin/selectSubject")
    public String selectSubject(@RequestBody(required = false) Subject subject){
        PageUtil pageUtil = DuUtil.setPageUtil(subject,0,10);
        List<Subject> listSubject = subjectService.selectSubject(subject,pageUtil);
        System.out.println(listSubject.toString());
        return DuUtil.success(listSubject.size()>0,listSubject,listSubject+"",pageUtil).toJSONString();
    }
}
